FROM golang:1.15-alpine AS builder
LABEL maintainer="fucaihe@gmail.com"
COPY . /app
WORKDIR /app
ENV GOPROXY=https://goproxy.cn,https://goproxy.io,https://gocenter.io,direct
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories; \
    apk add --no-cache g++; \
    go mod download; \
    CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /app/demo main.go

# FROM scratch
FROM alpine:latest
WORKDIR /app
COPY --from=builder /app/demo /app/demo
COPY --from=builder /app/conf /app/conf
RUN addgroup -S winfo && adduser -D -H -S winfo -G winfo; \
    sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories; \
    apk add --no-cache g++
USER winfo
ENTRYPOINT [ "/app/demo" ]
